var M=require("ming_node");
const MingSericalRunCode= require("./plugins/MingSericalReadLineRunCode");

sseApp=M.sseServer();
const app= M.server()
app.listen(8888);



mingSericalRunCode=  new MingSericalRunCode({
    com:"COM8",
    brand:9600,
    isNodeExecute:false,
    //接收单片机的请求
    async messageEvent(m){
        if(MingSericalRunCode.isNodeExecute){
            eval(m);
        }else {
            console.log("<==:"+m);
            sseApp.send({code:m});
        }
    }});



app.get("/sseServer",sseApp)


//控制单片机
app.post("/uartSend", async (req,res)=>{
    console.log("==>:"+req.body)
    await mingSericalRunCode.usartSend(req.body+"\n");
    res.send(M.successResult())
})


//控制单片机
app.get("/s/:cmd", async (req,res)=>{
    console.log("==>:"+req.params.cmd)
    sseApp.send({code:req.params.cmd});
    res.send(M.successResult())
})


